<?php
namespace app\erp_meixingtiyu\controller;

use think\facade\Request;
use app\erp_meixingtiyu\model\Banner as BannerModel;
use app\store\controller\Controller as StoreController;

class Banner extends StoreController
{
    // 后台获取banner分页列表
    public function list()
    {
        $banner = new BannerModel();
        $list = $banner->getList();

        return $this->renderSuccess($list->toArray());
    }

    public function add()
    {
        $params = Request::only(['name', 'link', 'image_id', 'sort' => 0]);
        $result = BannerModel::addBanner($params);

        return $this->renderSuccess($result->toArray(), '添加成功');
    }

    public function edit()
    {
        $params = Request::only(['banner_id', 'name', 'link', 'image_id', 'sort']);
        $result = BannerModel::editBanner($params);

        return $this->renderSuccess($result->toArray(), '编辑成功');
    }

    public function del($bannerId)
    {
        $banner = BannerModel::find($bannerId);
        $result = $banner->delete();

        return $this->renderSuccess([], '删除成功');
    }
}
